<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div id="app">
            {{msg|elps}}
        <ul>
            <!-- name 换成 msg -->
            <!-- <li v-for="item in arr">{{item.say|elps}}</li> -->
            <li v-for="item in arr">{{item.say|subStr(4,item.name)}}</li>
        </ul>
    </div>
    <script>
            //封装的管道符
        Vue.filter("elps",function(val){
            var str="";
            if(val.length>3){
                str=val.slice(0,4)+"..."
            }
            return str;
        }),
            //封装的管道符
            Vue.filter("subStr",function(val,length,name){
               // console.log(name)
            var str="";
            var length=length||3
            if(val.length>length){
                str=val.slice(0,length)+"..."
            }
            return str;
        })


    new Vue({
        el:"#app",
        data:{
                msg: "我爱北京天安门",
                arr:[
                    {name:"王健林",say:"要顶一个小目标",date:new Date()},
                    {name:"蓝精灵",say:"要顶一个小目标,",date:new Date()},
                    {name:"思聪",say:"要顶一个小目标",date:new Date()},
                ]
        },methods:{

        }
    })    
        
        
    </script>
    
</body>
</html>